<template>
    <el-dialog v-if="dialogVisible" :append-to-body="true" :close-on-click-modal='false' title="添加品牌" :visible.sync="dialogVisible" @close="resetForm('addForm')" width="400px">
        <el-form label-position="top" :model="addForm" :hide-required-asterisk='true' ref="addForm" :rules="addBrandRules" class="dialog_form">
            <el-form-item label="品牌名" prop="brand_name">
                <el-input v-model="addForm.brand_name" placeholder="请输入品牌名称"></el-input>
            </el-form-item>
            <el-form-item label="品牌标识ID" prop="brand_id">
                <el-input v-model="addForm.brand_id" placeholder="品牌标识ID"></el-input>
            </el-form-item>
            <el-form-item label="最低点赞数" prop="min_like_count">
                <template slot="label">
                    最低点赞数 <span style="color:red">(最小500)</span>
                </template>
                <el-input v-model="addForm.min_like_count" placeholder="最低点赞数，最小500"></el-input>
            </el-form-item>
            <!-- <el-form-item label="种草视频拉取天数" prop="zc_max_date">
                <el-select v-model="addForm.zc_max_date" placeholder="请选择" style="width:100%" disabled>
                    <el-option label="90天" :value="90"></el-option>
                    <el-option label="180天" :value="180"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="带货视频拉取天数" prop="dh_max_date">
                <el-select v-model="addForm.dh_max_date" placeholder="请选择" style="width:100%">
                    <el-option label="90天" :value="90"></el-option>
                    <el-option label="180天" :value="180"></el-option>
                </el-select>
            </el-form-item> -->
            <el-form-item label="飞瓜数据时间" prop="fx_date">
                <el-date-picker
                    v-model="addForm.fx_date"
                    value-format="yyyyMMdd"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                </el-date-picker>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="resetForm('addForm')" class="el-button-width">取 消</el-button>
            <el-button size="small" type="primary" @click="submitForm('addForm')" :disabled="loading" :loading="loading" class="el-button-width">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
export default {
    name: "",
    data() {
        return {
            loading: false,
            dialogVisible: false,
            addForm: {
                brand_name: "",
                brand_id: "",
                start_batch_num:"",
                end_batch_num  :"",
                min_like_count: null,
                fx_date:"",
                // zc_max_date:90,
                // dh_max_date:90,
            },
            addBrandRules: {
                brand_name: [
                    {
                        required: true,
                        message: "请输入品牌名称",
                        trigger: ["blur", "change"],
                    },
                ],
                brand_id: [
                    {
                        required: true,
                        message: "请输入品牌标识ID",
                        trigger: ["blur", "change"],
                    },
                ],
                min_like_count: [
                    {
                        required: true,
                        message: "请输入最低点赞数",
                        trigger: ["blur", "change"],
                    },
                ],
                zc_max_date: [
                    {
                        required: true,
                        message: "请选择",
                        trigger: ["blur", "change"],
                    },
                ],
                dh_max_date: [
                    {
                        required: true,
                        message: "请选择",
                        trigger: ["blur", "change"],
                    },
                ],
                fx_date:[
                    {
                        required: true,
                        message: "请选择起止时间",
                        trigger: ["blur", "change"],
                    },
                ]
            },
        };
    },
    created() {},
    methods: {
        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    const [startBatchNum, endBatchNum] = this.addForm.fx_date;
                    // 赋值给对应属性
                    this.addForm.start_batch_num = startBatchNum;
                    this.addForm.end_batch_num = endBatchNum;

                    this.loading = true;
                    const { data: res } = await this.$http.post(
                        "fxdata/fxboard/brandAdd",
                        this.addForm,
                    );
                    if (res.code !== 200) {
                        this.$message.error(res.msg);
                        this.loading = false;
                        return;
                    } else {
                        this.$emit("getBrandList");
                        this.$message({
                            message: "添加成功",
                            type: "success",
                        });
                        this.loading = false;
                        this.resetForm(formName);
                    }
                } else {
                    this.loading = false;
                    return false;
                }
            });
        },

        // 关闭重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dialogVisible = false;
        },
    },
    components: {},
};
</script>


<style scoped>
</style>
